package com.taobao.api.request;

import java.util.Map;

import com.taobao.api.ApiRuleException;
import com.taobao.api.TaobaoRequest;
import com.taobao.api.internal.util.RequestCheckUtils;
import com.taobao.api.internal.util.TaobaoHashMap;
import com.taobao.api.response.HanoiDataserviceWriteResponse;

/**
 * TOP API: taobao.hanoi.dataservice.write request
 * 
 * @author auto create
 * @since 1.0, 2013-08-03 16:51:00
 */
public class HanoiDataserviceWriteRequest implements TaobaoRequest<HanoiDataserviceWriteResponse> {

  private Map<String, String> headerMap = new TaobaoHashMap();
  private TaobaoHashMap       udfParams;                      // add
                                                              // user-defined
                                                              // text parameters
  private Long                timestamp;

  /**
   * 分配给调用方的名称信息，内部统计使用
   */
  private String              appName;

  /**
   * json对象，key为属性ID，值为需要回写的内容,如果属性值域不为空（通过taobao.hanoi.ranges.get获取）
   * 则需要把值转成key回写，并以逗号","隔开拼接成字符串
   */
  private String              data;

  /**
   * 回流数据的主键或上下文环境，如卖家id，类目id等。
   */
  private String              params;

  public void setAppName(String appName) {
    this.appName = appName;
  }

  public String getAppName() {
    return this.appName;
  }

  public void setData(String data) {
    this.data = data;
  }

  public String getData() {
    return this.data;
  }

  public void setParams(String params) {
    this.params = params;
  }

  public String getParams() {
    return this.params;
  }

  public Long getTimestamp() {
    return this.timestamp;
  }

  public void setTimestamp(Long timestamp) {
    this.timestamp = timestamp;
  }

  public String getApiMethodName() {
    return "taobao.hanoi.dataservice.write";
  }

  public Map<String, String> getTextParams() {
    TaobaoHashMap txtParams = new TaobaoHashMap();
    txtParams.put("app_name", this.appName);
    txtParams.put("data", this.data);
    txtParams.put("params", this.params);
    if (this.udfParams != null) {
      txtParams.putAll(this.udfParams);
    }
    return txtParams;
  }

  public void putOtherTextParam(String key, String value) {
    if (this.udfParams == null) {
      this.udfParams = new TaobaoHashMap();
    }
    this.udfParams.put(key, value);
  }

  public Class<HanoiDataserviceWriteResponse> getResponseClass() {
    return HanoiDataserviceWriteResponse.class;
  }

  public void check() throws ApiRuleException {
    RequestCheckUtils.checkNotEmpty(appName, "appName");
    RequestCheckUtils.checkNotEmpty(data, "data");
    RequestCheckUtils.checkNotEmpty(params, "params");
  }

  public Map<String, String> getHeaderMap() {
    return headerMap;
  }
}
